package com.ktjiaoyu.service.impl;

import com.ktjiaoyu.entity.Entry;
import com.ktjiaoyu.mapper.EntryMapper;
import com.ktjiaoyu.service.EntryService;
import com.ktjiaoyu.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/27  10:30
 */
@Service("entryService")
public class EntryServiceImpl implements EntryService {
    @Autowired
    private EntryMapper entryMapper;
    @Override
    public Page<Entry> findPage(Entry entry, Integer pageNo, Integer pageSize) {
        Page<Entry> page=new Page<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        Integer count=entryMapper.count(entry);
        page.setTotalCount(count);
        Integer pageBegin=(pageNo-1)*pageSize;
        List<Entry> data=entryMapper.pageList(entry,pageBegin,pageSize);
        page.setData(data);
        return page;
    }

    @Override
    public boolean insert(Entry entry) {
        return entryMapper.insert(entry) > 0;
    }

    @Override
    public Entry selectById(Long id) {
        return entryMapper.selectById(id);
    }

    @Override
    public boolean update(Entry entry) {
        return entryMapper.update(entry) > 0;
    }

    @Override
    public Entry selectByTitle(String title) {
        return entryMapper.selectByTitle(title);
    }

    @Override
    public boolean delete(Long id) {
        return entryMapper.delete(id)>0;
    }
}
